home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-16 | 3.7 KB | 163 lines | [TEXT/KAHL] |
- /*
- File: MathComponentCommon.c
-
- Contains: Math component routines.
-
- Written by: Gary Woodcock
-
- Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- */
-
- //-----------------------------------------------------------------------
- // Includes
-
- #include "MathComponent.h"
- #include "MathComponentCommon.h"
- #include "MathComponentPrivate.h"
- #include <OSUtils.h>
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathOpen (Handle storage,
- ComponentInstance self)
- {
- #pragma unused (storage)
-
- ComponentResult result = noErr;
- PrivateGlobals** globals;
-
- // Can we open another instance?
- if (CountComponentInstances ((Component) self) <= kMaxMathInstances)
- {
- // Did we get our storage?
- globals = (PrivateGlobals**) NewHandleClear (sizeof (PrivateGlobals));
- if (globals != nil)
- {
- // Keep a reference to self
- (*globals)->self = (Component) self;
-
- // Init private fields
- (*globals)->capturingComponentInstance = 0L;
- (*globals)->delegateComponent = 0L;
- (*globals)->delegateComponentInstance = 0L;
-
- // Set storage ref
- SetComponentInstanceStorage (self, (Handle) globals);
- }
- else // NewHandleClear failed
- {
- result = MemError();
- }
- }
- else // No more instances can be opened
- {
- result = kGenericError;
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathClose (Handle storage,
- ComponentInstance self)
- {
- ComponentResult result = noErr;
- PrivateGlobals** globals = (PrivateGlobals**) storage;
-
- // Do we have any clean up to do?
- if (globals != nil)
- {
- // Dispose globals
- DisposHandle ((Handle) globals);
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathCanDo (short selector)
- {
- // Case on the request code
- switch (selector)
- {
- // Component Manager request codes
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- case kComponentTargetSelect:
-
- // Math component request codes
- case kDoDivideSelect:
- case kDoMultiplySelect:
- {
- return (true);
- }
- case kComponentRegisterSelect: // Register request not supported
- default: // Not a request code we recognize
- {
- return (false);
- }
- }
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathVersion (void)
- {
- // Return the version info
- return (mathInterfaceRevision);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathTarget (Handle storage,
- ComponentInstance capturingComponent)
- {
- ComponentResult result = noErr;
- PrivateGlobals** globals = (PrivateGlobals**) storage;
-
- // Set reference to capturing component
- (*globals)->capturingComponentInstance = capturingComponent;
-
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathDoDivide (short numerator,
- short denominator,
- short *quotient)
- {
- ComponentResult result = noErr;
-
- if (denominator != 0)
- {
- *quotient = numerator/denominator;
- }
- else // Divide by zero not allowed
- {
- *quotient = 0;
- result = kGenericError;
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult _MathDoMultiply (short firstNum,
- short secondNum,
- short *multiplicationResult)
- {
- ComponentResult result = noErr;
-
- *multiplicationResult = firstNum * secondNum;
-
- return (result);
- }
-
- //-----------------------------------------------------------------------
-